<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //思考题1
        // var name = "The Windows";
        // var object = {
        //     name: "My Object",
        //     getNameFunc: function () {
        //         return function () {
        //             return this.name;
        //         };
        //     }
        // };
        // console.log(object.getNameFunc()()); //执行的window
        //拆分
        /*
        var f=object.getNameFunc();向当于执行了下面的操作
        var f=function(){
                    return this.name;
                };
        f();   相当于下面这个
        立即执行函数 function(){this}()，匿名函数的this指的是window
         */



        //思考题2
        var name = "The Window";
        var object = {
            name: "My Object",
            getNameFunc: function () {
                var that = this;   //这里的this怎么又指向object
                return function () {
                    return that.name;
                };
            }
        };
        console.log(object.getNameFunc()());
        //拆分
        /*
        var f=object.getNameFunc();
        var f=function(){      
                return that.name;
        }
        f();
         */
    </script>
</body>

</html>